PowerTCP Mail for .NET
GetBytes(Char[],Int32,Int32,Byte[],Int32) Method
See Also  Example Send comments on this topic.
Dart.PowerTCP.Mail Namespace > ImapUTF7Encoding Class > GetBytes Method : GetBytes(Char[],Int32,Int32,Byte[],Int32) Method




chars
The character array to encode.
charIndex
The index of the first character in chars to encode.
charCount
The number of characters to encode.
bytes
The byte array where the encoded results are stored.
byteIndex
The index of the first character in bytes where the encoded results are stored.
Encodes a specified range of elements from a Unicode character array, and stores the results in a specified range of elements in a byte array.

Syntax

Visual Basic (Declaration) 
Public Overloads Overrides Function GetBytes( _
   ByVal chars() As Char, _
   ByVal charIndex As Integer, _
   ByVal charCount As Integer, _
   ByVal bytes() As Byte, _
   ByVal byteIndex As Integer _
) As Integer
Visual Basic (Usage)Copy Code
Dim instance As ImapUTF7Encoding
Dim chars() As Char
Dim charIndex As Integer
Dim charCount As Integer
Dim bytes() As Byte
Dim byteIndex As Integer
Dim value As Integer
 
value = instance.GetBytes(chars, charIndex, charCount, bytes, byteIndex)
C# 
public override int GetBytes( 
   char[] chars,
   int charIndex,
   int charCount,
   byte[] bytes,
   int byteIndex
)
Managed Extensions for C++ 
public: int GetBytes( 
   char[]* chars,
   int charIndex,
   int charCount,
   byte[]* bytes,
   int byteIndex
) override 
C++/CLI 
public:
int GetBytes( 
   array<char>^ chars,
   int charIndex,
   int charCount,
   array<byte>^ bytes,
   int byteIndex
) override 

Parameters

chars
The character array to encode.
charIndex
The index of the first character in chars to encode.
charCount
The number of characters to encode.
bytes
The byte array where the encoded results are stored.
byteIndex
The index of the first character in bytes where the encoded results are stored.

Return Value

The number of bytes stored in bytes.

Exceptions

ExceptionDescription
System.ArgumentExceptionbyteIndex is equal to the length of bytes. -or-No bytes have been stored in bytes.-or-An invalid high or low member of a surrogate pair was encountered during encoding.
System.ArgumentNullExceptionThe chars or bytes parameter is a null reference.
System.ArgumentOutOfRangeExceptionThe charIndex, charCount, or byteIndex parameter is less than zero. -or-The sum of charIndex and charCount is greater than the length of chars.-or-byteIndex is greater than the length of bytes.

Example

The following example demonstrates encoding/decoding data using the ImapUTF7Encoding class.
Visual BasicCopy Code
Private Sub ImapUTF7Test()

   ' Create Unicode character array
   ' ChrW(35)  = #
   ' ChrW(37)  = %
   ' ChrW(928) = Pi
   ' ChrW(931) = Sigma
   Dim chars() As Char = {ChrW(35), ChrW(37), ChrW(928), ChrW(931)}

   ' Initialize ImapUTF7 encoder
   Dim ImapUTF7 As New ImapUTF7Encoding()

   ' Determine how big target byte array needs to be 
   Dim Count As Integer = ImapUTF7.GetByteCount(chars, 0, chars.Length)
   ' You could also use the following to get the maximum size
   ' Dim Count As Integer = ImapUTF7.GetMaxByteCount(chars.Length)
   Debug.WriteLine(Count & " bytes needed to encode characters.")

   ' Initialize target byte array
   Dim Bytes(Count - 1) As Byte

   ' Encode data
   Count = ImapUTF7.GetBytes(chars, 0, chars.Length, bytes, 0)
   Debug.WriteLine(Count & " bytes encoded.")

   ' Show encoded bytes
   Dim B As Byte
   For Each B In Bytes
      Debug.WriteLine(B)
   Next

   ' Now to decode...first determine how big target char array needs to be
   Count = ImapUTF7.GetCharCount(Bytes, 0, Bytes.Length)
   ' You could also use the following to get the maximum size
   ' Count = ImapUTF7.GetMaxCharCount(Bytes.Length)
   Debug.WriteLine(Count & " characters needed to decode bytes.")

   ' Initialize target char array
   ReDim chars(Count - 1)

   ' Decode data
   Count = ImapUTF7.GetChars(Bytes, 0, Bytes.Length, chars, 0)
   Debug.WriteLine(Count & " bytes decoded.")

   ' Show decoded characters
   Dim C As Char
   For Each C In chars
      Debug.WriteLine(C)
   Next
End Sub
C#Copy Code
private void ImapUTF7Test()
{
   // Create Unicode character array
   char[] chars = {
      '\u0023', // #
      '\u0025', // %
      '\u03a0', // Pi
      '\u03a3'  // Sigma
   };

   // Initialize ImapUTF7 encoder
   ImapUTF7Encoding ImapUTF7 = new ImapUTF7Encoding();

   // Determine how big target byte array needs to be 
   int count = ImapUTF7.GetByteCount(chars, 0, chars.Length);
   // You could also use the following to get the maximum size
   // int count = ImapUTF7.GetMaxByteCount(chars.Length);
   Debug.WriteLine(count + " bytes needed to encode characters.");

   // Initialize target byte array
   byte[] bytes = new byte[count];

   // Encode data
   count = ImapUTF7.GetBytes(chars, 0, chars.Length, bytes, 0);
   Debug.WriteLine(count + " bytes encoded.");

   // Show encoded bytes
   foreach(byte b in bytes)
      Debug.WriteLine(b);

   // Now to decode...first determine how big target char array needs to be
   count = ImapUTF7.GetCharCount(bytes, 0, bytes.Length);
   // You could also use the following to get the maximum size
   // count = ImapUTF7.GetMaxCharCount(bytes.Length);
   Debug.WriteLine(count + " characters needed to decode bytes.");

   // Initialize target char array
   chars = new char[count];

   // Decode data
   count = ImapUTF7.GetChars(bytes, 0, bytes.Length, chars, 0);
   Debug.WriteLine(count + " bytes decoded.");

   // Show decoded characters
   foreach(char c in chars)
      Debug.WriteLine(c);
}

Remarks

Use ImapUTF7Encoding.GetByteCount to calculate exactly, or ImapUTF7Encoding.GetMaxByteCount to calculate at most, the array size required by the ImapUTF7Encoding.GetBytes method to store encoded characters.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.